<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>菜鸟教程(runoob.com)</title>
    <script src="../js/vue.min.js"></script>
    <script src="../js/vuex.js"></script>
</head>
<body>
<div id="app">
    <p>{{count}}
        <button @click="inc">+</button>
        <button @click="dec">-</button>
    </p>
</div>
<script>

    const store = new Vuex.Store({
                state: {
                    count: 0
                },
                mutations: {
                    inc:function(state){ state.count++},
                    dec:function(state){ state.count--}

    }
    })

    const app = new Vue({
        el: '#app',
        computed: {
            count () {
                return store.state.count
            }
        },
        methods: {
            inc () {
                store.commit('inc')
            },
            dec () {
                store.commit('dec')
            }
        }
    })
</script>
</body>
</html>
